<?php

class ThreadsReply extends \Phalcon\Mvc\Model
{

    /**
     *
     * @var integer
     */
    public $id;

    /**
     *
     * @var integer
     */
    public $forum_id;

    /**
     *
     * @var integer
     */
    public $user_id;

    /**
     *
     * @var string
     */
    public $content;

    /**
     *
     * @var string
     */
    public $date_created;

    /**
     * Independent Column Mapping.
     */
    public function columnMap()
    {
        return array(
            'id' => 'id', 
            'forum_id' => 'forum_id', 
            'user_id' => 'user_id', 
            'content' => 'content', 
            'date_created' => 'date_created'
        );
    }

    public function beforeValidationOnCreate()
    {
        $this->date_created = CURR_DATE;
    }

    public function listReply($forum_id)
    {
        $phql = "SELECT tr.id,tr.forum_id,tr.user_id,tr.content,tr.date_created,
                uat.username,uat.fname,uat.lname,uat.profile_pic
                FROM ThreadsReply tr 
                LEFT JOIN UserAccountTb uat on uat.id = tr.user_id
                WHERE tr.forum_id = ?0
                ORDER BY tr.date_created DESC";
        $data = $this->modelsManager->executeQuery($phql,array(0=>$forum_id));
        return $data;
    }

    public function listReplyInfo($id){
        $phql = "SELECT tr.id,tr.forum_id,tr.user_id,tr.content,tr.date_created,
                uat.username,uat.fname,uat.lname,uat.profile_pic
                FROM ThreadsReply tr 
                LEFT JOIN UserAccountTb uat on uat.id = tr.user_id
                WHERE tr.id = ?0
                ORDER BY tr.date_created DESC";
        $data = $this->modelsManager->executeQuery($phql,array(0=>$id));
        return $data[0];   
    }
}

